import React, { Component } from "react";
import { Button } from "antd";
import { WeaDialog, WeaMap, WeaLocaleProvider } from 'ecCom';
import { getLocationInfoData } from '../../util/signUtil'
const getLabel = WeaLocaleProvider.getLabel;
export default class MapDialog extends Component {
  constructor(props) {
    super(props);
    let positionObj = getLocationInfoData(props.location);
    let positionArr = [positionObj.longitude, positionObj.latitude] || [];
    let info = {
      name: positionObj.name
    }
    this.state = {
      visible: true,
      locationInfo: {
        info: info || {},
        position: positionArr || [],
        citycode: ""
      }

    };
  }
  onCancel = () => {
    let locationInfo = {
      info: {},
      position: [],
    }
    this.setState({ visible: false,locationInfo: locationInfo });
    $("#map-dialog").remove();
  }
  setVisible = bool => this.setState({ visible: bool });

  componentWillReceiveProps(nextProps){
    let positionObj = getLocationInfoData(nextProps.location);
    // let positionArr = [positionObj.longitude, positionObj.latitude] || [];
    let positionArr = [positionObj.latitude, positionObj.longitude] || [];
    let info = {
      name: positionObj.name
    }
    let locationInfo = {
      info: info,
      position: positionArr,
    }
    this.setState({
      visible: true,
      locationInfo:locationInfo
    })
  }
  
  render() {
    const { setLayout=window.document.body } = this.props;
    const { visible,locationInfo} = this.state;
    const { position, info} = locationInfo;

    const buttons = [
      <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@kvfbks@close`} onClick={() => {this.onCancel()}}
          type="ghost" 
      >
          {getLabel(309,'关闭')}
      </Button>
    ];
    return (
      <div className='map-dialog-map'>
          <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@andq8w`}
              visible={visible}
              title={getLabel('386191','查看位置')}
              style={{ width: 900, height: 600 }}
              buttons={buttons}
              onCancel={() => this.onCancel()}
              icon={'icon-coms-workflow'}
              iconBgcolor={'rgb(0, 121, 222)'}
              layout={setLayout} 
          > 
          <WeaMap ecId={`${this && this.props && this.props.ecId || ''}_WeaMap@r5jbb6`}
              zoom={14}
              position={position}
              info={info}
              showInfoWindow={true}
              showInfoWin={true}
            />
        </WeaDialog>
      </div>
   
    );
  }
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 